package com.zretc.controller;

import com.zretc.entity.Position;
import com.zretc.entity.ResponseResult;
import com.zretc.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 何亮龙
 * 职位控制层
 */
@RestController
@RequestMapping("/organization/position")
public class PositionController {
    @Autowired
    private PositionService positionService;
    @GetMapping("/getAllPositions")
    public List<Position> getAllPositions() {
        return positionService.getAllPositions();
    }

    @PostMapping("/addPosition")
    public ResponseResult addPosition(@RequestBody Position position) {
        if (positionService.addPosition(position) == 1) {
            return ResponseResult.ok("添加成功!");
        }
        return ResponseResult.error("添加失败!");
    }

    @PutMapping("/updatePositions")
    public ResponseResult updatePositions(@RequestBody Position position) {
        if (positionService.updatePositions(position) == 1) {
            return ResponseResult.ok("更新成功!");
        }
        return ResponseResult.error("更新失败!");
    }

    @DeleteMapping("/deletePositionById/{id}")
    public ResponseResult deletePositionById(@PathVariable Integer id) {
        if (positionService.deletePositionById(id) == 1) {
            return ResponseResult.ok("删除成功!");
        }
        return ResponseResult.error("删除失败!");
    }

    @DeleteMapping("/deletePositionsByIds")
    public ResponseResult deletePositionsByIds(Integer[] ids) {
        if (positionService.deletePositionsByIds(ids) == ids.length) {
            return ResponseResult.ok("删除成功!");
        }
        return ResponseResult.error("删除失败!");
    }
}
